package generic.form;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;

import javax.swing.filechooser.FileFilter;

public abstract class GenericInOutFile {
	
	private String path;
	private String dialogTitle;
	private File pathFile;
	private Integer time;
	
	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}
	
	public void setDialogTitle(String dialogTitle) {
		this.dialogTitle = dialogTitle;
	}
	
	public String getDialogTitle() {
		return this.dialogTitle;
	}
	
	public void setPathFile(File pathFile) {
		this.pathFile = pathFile;
	}

	public File getPathFile() {
		return this.pathFile;
	}

	public Integer getTime() {
		return time;
	}
	
	public void setTime(Integer time) {
		this.time = time;
	}
	
	public int getSizeFile() {
		int qtdLinha = -1;
		try {
			File arquivoLeitura = new File(getPathFile().toString());
			LineNumberReader linhaLeitura = new LineNumberReader(new FileReader(arquivoLeitura));
			linhaLeitura.skip(arquivoLeitura.length()); 
			qtdLinha = linhaLeitura.getLineNumber();
			linhaLeitura.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return qtdLinha;
	}
	
	public FileFilter criarFiltroTxt() {
		return new FileFilter() {
			
			@Override
			public String getDescription() {
				return "*.txt";
			}
			
			@Override
			public boolean accept(File arg0) {
				if (arg0.getName().toUpperCase().endsWith(".TXT"))
					return true;
				if (arg0.getName().length() == arg0.getName().replace(".", "").length())
					return true;
				return false;
			}
		};
	}
}
